//
// Created by weslywang on 2020/4/25.
//
#include "../common/common.h"

void dfs(TreeNode *root, vector<TreeNode *> *preList) {
    if (!root) {
        return;
    }
    preList->push_back(root);
    dfs(root->left, preList);
    dfs(root->right, preList);
}

void flatten(TreeNode *root) {
    if (!root) {
        return;
    }
    vector<TreeNode *> store;
    dfs(root, &store);
    TreeNode *head = root;
    for (int i = 1; i < store.size(); i++) {
        head->left = NULL;
        head->right = store[i];
        head = store[i];
    }
}

int main() {
    Common common;
    int a[] = {1, 2, 3, 4, 5};
    vector<vector<int>> numList = common.loadData();
    for (int i = 0; i < numList.size(); i++) {
        TreeNode *root = common.makeTree(numList[i]);
        common.printTree(root);
        flatten(root);
        cout << "**************" << endl;
    }
    return 0;
}